//
//  GatherSingleViewController.m
//  TryShopping
//
//  Created by panquanReabam.com on 16/12/23.
//  Copyright © 2016年 RuiBen. All rights reserved.
//

#import "GatherSingleViewController.h"
#import "SelectedGoodNewViewController1.h"
#import "SelectedGoodNewHeaderDataModel.h"
#import "FMDB.h"
#import "PlaceOrderSpecTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "specTableViewDataModel.h"
#import "WhsInAddViewController.h"
#import "OrderExtAddViewController.h"
#import "BusinessCheckVouchContinueViewController.h"
#import "NoSpecFmdbModel.h"
#import "NoSpecFmdbTool.h"
#import "HasSpecFmdbModel.h"
#import "HasSpecFmdbTool.h"
#import "LeftJoinFmdbModel.h"
#import "fmDataModel.h"
#import "GatherSingleCell.h"
#import "GetAddBuyGoodsViewController.h"
#import "ShopCartSuitsViewController.h"
#import "ReabamSingleton.h"
#import "ShopCartTrunDonationViewController.h"
#import "scanViewController.h"
#import "GetAddBuyGoodsViewController.h"
@interface GatherSingleViewController ()<PlaceOrderSpecCellDelegate,GatherSingleCellDelegate,GetAddBuyGoodsViewControllerDelegate,UIGestureRecognizerDelegate,UITableViewDelegate,UITableViewDataSource,ShopCartSuitsViewControllerDelegate,ShopCartTrunDonationViewControllerDelegate,UITextFieldDelegate,scanViewControllerDelegate>
{
    NSMutableArray *headerModelArray;
    NSMutableArray *isCurrent;
    NSMutableArray *isAvailable;
    NSMutableArray *planId;
    NSMutableArray *sptypeName;
    NSMutableArray *planTitle;
    UIView*modifyThePreferentialView;
    NSString *userToken;
    NSString *isSuitStr;
    NSString *shopCartIdStr;
    NSInteger parentTag;
    NSString*tagStr;
    UITableView*table_list;
    NSString*isCurrentPlanId;
    ReabamSingleton*commdity;
    NSUInteger h;
    UIView*operationsView;
    bool saveAccount;
    NSArray*operationsArray;
    NSArray*ColorArray;
    UITextField*searchTextField;
    UIButton*CombinationOfGiftBtn;
    UIView*HeaderView;
    UIView*noDataView;
}
@property (retain, nonatomic) UIAlertView* alt;
@end

@implementation GatherSingleViewController
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    commdity=[ReabamSingleton shared];
    self.memberDict=commdity.dataMemberDict;
    [self setNavigation];
    [self initDataBase];
}
-(void)viewDidLoad{
    
    [super viewDidLoad];
    
    [self setAutoLayout];
    UIButton* operationsBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0.0,  60/2, 60/2)];
    [operationsBtn setBackgroundImage:[UIImage imageNamed:@"saoyisao_new"] forState:UIControlStateNormal];
    [operationsBtn addTarget:self action:@selector(operations:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:operationsBtn];
    self.navigationItem.rightBarButtonItem = myBtnBtn;
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    userToken = [user objectForKey:@"tokenId"];
   
    [_tableView registerClass:[GatherSingleCell class] forCellReuseIdentifier:@"GatherSingleViewController"];
    UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
    _tableView.tableFooterView=view1;
   
}

-(void)chooseBtn:(UIButton*)sender{

    GetAddBuyGoodsViewController *detailViewController = [[GetAddBuyGoodsViewController alloc] init];
    detailViewController.mDelegate=self;
   
    detailViewController.shopCartId=self.shopCartId;
    
    detailViewController.chooseStr=CombinationOfGiftBtn.titleLabel.text;
    [self.navigationController pushViewController:detailViewController animated:YES];

}
-(void)operations:(UIButton*)sender{
   
    scanViewController *detailViewController = [[scanViewController alloc] init];
    detailViewController.delegate=self;
    //detailViewController.typeString=scanTypeStr;
   
   [self.navigationController pushViewController:detailViewController animated:YES];


}

-(void)update:(NSString *)updateStr{
    //    [self initDataBase];
    
}

-(void)scanGoodInfoData:(NSString*)codeStr{
    searchTextField.text=codeStr;
 [self getNoSpecDataFromDB];
}
-(void)initDataBase
{
    [self getNoSpecDataFromDB];
}
-(void )getNoSpecDataFromDB
{
    [HeaderView removeFromSuperview];
    [noDataView removeFromSuperview];
    HeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
    HeaderView.backgroundColor=zuiqianhuiColor;
    _tableView.tableHeaderView=HeaderView;
   
    
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:userToken forKey:@"tokenId"];
        [params setObject:_shopCartId forKey:@"shopCartId"];
        [params setObject:searchTextField.text forKey:@"sword"];
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSLog(@"Business/ShopCart/Detail******===%@",params);
        [HttpRequest requestData:@"Business/ShopCart/CombiItems" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                NSLog(@"Business/ShopCart/Detail******===%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                     headerModelArray=[NSMutableArray array];
                    [Global hideProgressHUDInternal:self.view];
                    _Dict=severDataDict.dataDict;
                    _totalLabel.text=[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"ySelQty"] ];
                    _totalLabel.layer.cornerRadius=10;
                    _totalLabel.layer.masksToBounds=YES;
                    _totalPromotionMoney.text=[NSString stringWithFormat:@"%.2f",[[severDataDict.dataDict objectForKey:@"ySelRealMoney"] doubleValue]];
                    _planTitle.text=[NSString stringWithFormat:@"%@",[[severDataDict.dataDict objectForKey:@"shopCart"]objectForKey:@"planTitle"] ];
                    NSMutableArray *mArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                   
                     if (mArray.count>0) {
                    for (NSDictionary* dicc in mArray )
                    {
                        SelectedGoodNewHeaderDataModel *model=[SelectedGoodNewHeaderDataModel mj_objectWithKeyValues:dicc];
                        [headerModelArray addObject:model];
                        
                    }
                    
                   
                         
                    }else{
                        noDataView=[[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight/2-50, ScreenWidth, 80)];
                        [self.view addSubview:noDataView];
                        UIImageView*noImage=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/2-47, 0, 94, 51)];
                        noImage.image=[UIImage imageNamed:@"meiyoushuju"];
                        [noDataView addSubview:noImage];
                        UILabel*noLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,65, ScreenWidth, 14)];
                        noLabel.text=@"没有列表数据，赶紧去添加！";
                        noLabel.textColor=zhonghuiColor; noLabel.font=[UIFont systemFontOfSize:14];
                        noLabel.textAlignment=NSTextAlignmentCenter;
                        [noDataView addSubview:noLabel];
                        
                    }

                    
                    
                    
                    if ([[NSString stringWithFormat:@"%@",[[severDataDict.dataDict objectForKey:@"shopCart"]objectForKey:@"planStatus"] ]isEqualToString:@"Y"]) {
                        CombinationOfGiftBtn=[[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-100, 0, 60, 42)];
                        if ([[NSString stringWithFormat:@"%@",[[severDataDict.dataDict objectForKey:@"shopCart"]objectForKey:@"spType"] ]isEqualToString:@"buyAddPrice"]) {
                             [CombinationOfGiftBtn setTitle:@"去换购" forState:UIControlStateNormal];
                            [CombinationOfGiftBtn setTitleColor:[UIColor colorWithRed:255/255.0 green:51/255.0 blue:0/255.0 alpha:1]  forState:UIControlStateNormal];
                            CombinationOfGiftBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
                            CombinationOfGiftBtn .titleLabel.font=[UIFont systemFontOfSize:12];
                            [CombinationOfGiftBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
                             [HeaderView addSubview:CombinationOfGiftBtn];
                            UIButton*chooseBtn1=[[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-40, 5, 33, 33)];
                            [chooseBtn1 setTitle:@"" forState:UIControlStateNormal];
                            [chooseBtn1 setTitleColor:[UIColor clearColor]  forState:UIControlStateNormal];
                            [chooseBtn1 setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
                            [chooseBtn1 addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
                            [HeaderView addSubview:chooseBtn1];

                        }else{
                            if ([[NSString stringWithFormat:@"%@",[[severDataDict.dataDict objectForKey:@"shopCart"]objectForKey:@"hasGift"] ]isEqualToString:@"Y"]) {
                                
                                 [CombinationOfGiftBtn setTitle:@"领赠品" forState:UIControlStateNormal];
                                [CombinationOfGiftBtn setTitleColor:[UIColor colorWithRed:255/255.0 green:51/255.0 blue:0/255.0 alpha:1]  forState:UIControlStateNormal];
                                CombinationOfGiftBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
                                CombinationOfGiftBtn .titleLabel.font=[UIFont systemFontOfSize:12];
                                [CombinationOfGiftBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
                                 [HeaderView addSubview:CombinationOfGiftBtn];
                                UIButton*chooseBtn1=[[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-40, 5, 33, 33)];
                                [chooseBtn1 setTitle:@"" forState:UIControlStateNormal];
                                [chooseBtn1 setTitleColor:[UIColor clearColor]  forState:UIControlStateNormal];
                                [chooseBtn1 setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
                                [chooseBtn1 addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
                                [HeaderView addSubview:chooseBtn1];

                            }else{
                                
                                
                                
                            }

                            
                            
                        
                        }
                       
                        
                    }else{
                        
                    }

                    
                    UILabel *planTitleLabel=[[UILabel alloc] initWithFrame:CGRectMake(15, 0,ScreenWidth, 40)];
                    planTitleLabel.text=[NSString stringWithFormat:@"%@",[[severDataDict.dataDict objectForKey:@"shopCart"]objectForKey:@"planTitle"] ];
                    planTitleLabel.textColor=zhonghuiColor;
                    planTitleLabel.font=[UIFont systemFontOfSize:13];
                    [HeaderView addSubview:planTitleLabel];
                    [_tableView reloadData];
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                }
                
            }else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:severDataDict.resultStr view:self.view];
            }
        }];
        
        
        
       
}
-(void)ShopCartMerge:(NSString *)pidStr :(NSString *)specIdStr :(NSString *)ySelQty {
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:userToken forKey:@"tokenId"];
    
    [params setValue:ySelQty  forKey:@"quantity"];
    [params setValue:[[_Dict objectForKey:@"shopCart"]objectForKey:@"planId"]  forKey:@"planId"];
    [params setValue:isSuitStr  forKey:@"isSuit"];
    [params setValue:pidStr forKey:@"itemId"];
    [params setValue:specIdStr forKey:@"specId"];
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:3 view:self.view];
    NSLog(@"params====%@",params);
    [HttpRequest requestData:[NSString stringWithFormat:@"Business/ShopCart/%@",@"Merge"] params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                NSLog(@"SCANrequestItemDetail====%@",severDataDict.dataDict);
                [self getNoSpecDataFromDB];
            }else
            {
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
                
            }
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
    }];
    
    
}

-(void)subtractCountBtn:(NSString *)subtractCountBtn :(NSString *)isSuit{
      SelectedGoodNewHeaderDataModel *headerModel=headerModelArray[subtractCountBtn.intValue];
        NSString *oriCount=[NSString stringWithFormat:@"%d",[headerModel.shopCartQty intValue]];
        if ( [headerModel.shopCartQty intValue]==1) {
            
            if([[NSString stringWithFormat:@"%@",[[_Dict objectForKey:@"shopCart"]objectForKey:@"specId"] ]isEqualToString:headerModel.specId]) {
            
                [self showAlertMessage:@"主商品不能减到为0"];
            }else{
            
                oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]-1];
                [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
            }

            
        }else{
            
            oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]-1];
            [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
            
        }
       
    
  
}
-(void)addCountBtn:(NSString *)addCountBtn :(NSString *)isSuit
{
    isSuitStr=isSuit;
    
    SelectedGoodNewHeaderDataModel *headerModel=headerModelArray[addCountBtn.intValue];
    if ([isSuitStr isEqualToString:@"Y"]) {
        if ([headerModel.shopCartQty  intValue]<[ headerModel.specInv intValue]) {
            NSString *oriCount=[NSString stringWithFormat:@"%d",[headerModel.shopCartQty intValue]];
            oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]+1];
            [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
        }else{
            NSString *oriCount=[NSString stringWithFormat:@"%d",[headerModel.shopCartQty intValue]];
            oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]+1];
            [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
            
            [self showAlertMessage:@"已超出商品库存量"];
        }
    }else{
        
        if ([headerModel.shopCartQty  intValue]<[ headerModel.specInv intValue]) {
            NSString *oriCount=[NSString stringWithFormat:@"%d",[headerModel.shopCartQty intValue]];
            oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]+1];
            [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
        }else{
            NSString *oriCount=[NSString stringWithFormat:@"%d",[headerModel.shopCartQty intValue]];
            oriCount=[NSString stringWithFormat:@"%d",[oriCount intValue]+1];
            [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
            [self showAlertMessage:@"已超出商品库存量"];
        }
        
    }
    
}


- (void)chooseBtn:(NSString *)chooseBtn :(NSString *)chooseStr{
    if ([chooseStr isEqualToString:@"选择套装"]||[chooseStr isEqualToString:@"重选套装"]){
        
        SelectedGoodNewHeaderDataModel *headerModel=headerModelArray[chooseBtn.intValue];
        ShopCartSuitsViewController *detailViewController = [[ShopCartSuitsViewController alloc] init];
        detailViewController.mDelegate=self;
        detailViewController.chooseStr=chooseStr;
        detailViewController.shopCartId=headerModel.id;
        [self.navigationController pushViewController:detailViewController animated:YES];
        
    }else{
        SelectedGoodNewHeaderDataModel *headerModel=headerModelArray[chooseBtn.intValue];
        GetAddBuyGoodsViewController *detailViewController = [[GetAddBuyGoodsViewController alloc] init];
        detailViewController.mDelegate=self;
        detailViewController.chooseStr=chooseStr;
        detailViewController.shopCartId=headerModel.id;
        [self.navigationController pushViewController:detailViewController animated:YES];
        
    }
}

-(void)CountBtn:(NSString *)CountBtn :(NSString *)isSuit{
    isSuitStr=isSuit;
    SelectedGoodNewHeaderDataModel *headerModel=headerModelArray[CountBtn.intValue];
       UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"数量"
                               
                                                        message:@"请输入修改的数量"
                               
                                                       delegate:self
                               
                                              cancelButtonTitle:@"取消"
                               
                                              otherButtonTitles:@"确定",nil];
    alertView.tag=CountBtn.intValue;
    [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
    
    
    UITextField * text1 = [alertView textFieldAtIndex:0];
    
  
    NSString *oriCount=[NSString stringWithFormat:@"%d",[headerModel.shopCartQty intValue]];
    text1.text=oriCount;
    
    tagStr=[NSString stringWithFormat:@"%d",CountBtn.intValue];
    text1.contentVerticalAlignment= UIControlContentVerticalAlignmentCenter;
    text1.keyboardType = UIKeyboardTypeNumberPad;
    [alertView show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
        if (buttonIndex == 1)
        {
            UITextField * text1 = [alertView textFieldAtIndex:0];
            text1.contentVerticalAlignment= UIControlContentVerticalAlignmentCenter;
            text1.keyboardType = UIKeyboardTypeNumberPad;
            SelectedGoodNewHeaderDataModel *headerModel=headerModelArray[alertView.tag];
            if ([text1.text  intValue]<=[headerModel.specInv intValue]) {
                
                if ( [text1.text  intValue]==0) {
                    
                    if([[NSString stringWithFormat:@"%@",[[_Dict objectForKey:@"shopCart"]objectForKey:@"specId"] ]isEqualToString:headerModel.specId]) {
                        
                        [self showAlertMessage:@"主商品不能减到为0"];
                    }else{
                        
                        NSString *oriCount=[NSString stringWithFormat:@"%d",[text1.text intValue]];
                        [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
                    }
                    
                    
                }else{
                    
                    NSString *oriCount=[NSString stringWithFormat:@"%d",[text1.text intValue]];
                    [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
                    
                }
                

                
                
              
                
            
            }else{
               
                
                
                [self showAlertMessage:@"已超出商品库存量"];
                if ( [text1.text  intValue]==0) {
                    
                    if([[NSString stringWithFormat:@"%@",[[_Dict objectForKey:@"shopCart"]objectForKey:@"specId"] ]isEqualToString:headerModel.specId]) {
                        
                        [self showAlertMessage:@"主商品不能减到为0"];
                    }else{
                        
                        NSString *oriCount=[NSString stringWithFormat:@"%d",[text1.text intValue]];
                        [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
                    }
                    
                    
                }else{
                    
                    NSString *oriCount=[NSString stringWithFormat:@"%d",[text1.text intValue]];
                    [self ShopCartMerge:headerModel.itemId :headerModel.specId :oriCount];
                    
                }
                
                    
                    
        }
                    
            
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
   return headerModelArray.count;
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
 
        return 120;

    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    GatherSingleCell*cell = [tableView dequeueReusableCellWithIdentifier:@"GatherSingleViewController"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        for (UIView *view in [cell subviews]){
            [view removeFromSuperview];
        }
        cell.mDelegate=self;
        cell.GoodsInOrderListModel=headerModelArray[indexPath.row];
        cell.addCountBtn.tag=indexPath.row;
        cell.subtractCountBtn.tag=indexPath.row;
        cell.CountBtn.tag=indexPath.row;
        cell.chooseBtn.tag=indexPath.row;
        cell.chooseBtn1.tag=indexPath.row;
        cell.modifyTheBtn.tag=indexPath.row;
    
    
        return cell;
}
#pragma mark  -select cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
}
-(void)setAutoLayout
{
       [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left)  ;
        make.right.equalTo(self.view.mas_right)   ;
        make.bottom.equalTo(self.view.mas_bottom);
        make.top.equalTo(self.view.mas_top).with.offset(0);
    }];
    [_lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left) ;
        make.right.equalTo(_submitConfirmBtn.mas_left) ;
        make.height.equalTo(@48) ;
        make.bottom.equalTo(self.view.mas_bottom);
        
    }];
    [_submitConfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right) ;
        make.width.equalTo(@160) ;
        make.height.equalTo(@48) ;
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    [_totalCountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left) ;
        make.right.equalTo(_submitConfirmBtn.mas_left) ;
        make.height.equalTo(@48) ;
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
}


- (IBAction)confirmBtnClick:(id)sender {
    
    
    SelectedGoodNewViewController1 *homeVC1 = [[SelectedGoodNewViewController1 alloc] init];
    UIViewController *target1 = nil;
    for (UIViewController * controller in self.navigationController.viewControllers) { //遍历
        if ([controller isKindOfClass:[homeVC1 class]]) { //这里判断是否为你想要跳转的页面
            target1 = controller;
        }
    }
    [self.navigationController popToViewController:target1 animated:YES]; //跳转

   
}

-(void)setNavigation
{
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    
    UIView*titleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 32.5)];
    titleView.backgroundColor=zuiqianhuiColor;
    self.navigationItem.titleView=titleView;
    
    
    UIButton *sxBtn1 = [[UIButton alloc] initWithFrame:CGRectMake( 5, 5, 25, 25)];
    [sxBtn1 setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
    [titleView addSubview:sxBtn1];
    
    
    searchTextField = [[UITextField alloc] initWithFrame:CGRectMake(sxBtn1.right,0, ScreenWidth*400/750,35)];
    [searchTextField setBorderStyle:   UITextBorderStyleNone]; //外框类型
    searchTextField.placeholder = @" 请输入条形码／商品名"; //默认显示的字
    searchTextField.font = [UIFont systemFontOfSize: 14];
    searchTextField.tag=22;
//    searchTextField.keyboardType = UIKeyboardTypeDecimalPad;
    searchTextField.returnKeyType = UIReturnKeyDone;
    searchTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    searchTextField.delegate = self;
    [titleView addSubview:searchTextField];
    
    UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:16];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    searchTextField.inputAccessoryView = myToolBar;
    
    
    self.navigationController.navigationBar.barStyle =UIBaselineAdjustmentNone ;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
     [self getNoSpecDataFromDB];
 
     [searchTextField resignFirstResponder];
    return YES;
}

-(void)OnTapDone{
   
    [searchTextField resignFirstResponder];
}
-(void)BackAction:(UIButton *)sender{
    
      [self.navigationController popViewControllerAnimated:YES];
}
- (void)showAlertMessage:(NSString *)msg
{
    _alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [_alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.5f];
}
- (void)hideAlert
{
    if (_alt != nil)
    {
        [_alt dismissWithClickedButtonIndex:0 animated:YES];
        _alt = nil;
    }
}

@end
